/*
 * @Author: your name
 * @Date: 2021-07-16 18:01:39
 * @LastEditTime: 2023-08-08 14:45:16
 * @LastEditors: tzq
 * @Description: In User Settings Edit
 * @FilePath: \bdcar-net\src\store\mutations.js
 */
import {
  UPDATE_ACTIVEMENU, //当前活动菜单
  UPDATE_ISLOADEDMAP, //地图加载状态
  UPDATE_CLIENT, //浏览器宽高
  UPDATE_ACTIVEMENULIST, //缓存菜单列表存储
  UPDATE_ISPACKUP, //收缩菜单栏
  UPDATE_CURRENTUSER, //更新当前用户
  UPDATE_JUMPPAGE, //当前选择的车辆用以显示气泡
  UPDATE_MAPWINDOWLIST, //地图标注:commond命令类型 1删除一个点，2清空，3添加一个点，4添加一类
  UPDATE_ISSHOWREPLYDOM, //是否显示应答界面
  UPDATE_ISSHOWALERTDOM, //是否显示实时报警界面
  UPDATE_REPLYNUM, //应答消息数目
  UPDATE_ALERTNUM, //实时报警数目
  UPDATE_SYSTITLE, //系统标题设置
  // UPDATE_MAPREFRESH, //地图刷新频率
  // UPDATE_MAPCENTERLNG, //地图中心经度
  // UPDATE_MAPCENTERLAT, //地图中心纬度
  UPDATE_MAPSETTINGS, //
  GET_AVAILABLEMENULIST
} from "./types"

export default {
  [UPDATE_ACTIVEMENU](state, data) {
    state.activeMenu = data;
    // 移植到vue3时删除
    if (data != 'realtimePosition' && document.getElementsByClassName("virtual-list").length > 0) localStorage.setItem("vlTreeScrollTop", document.getElementsByClassName("virtual-list")[0]?.scrollTop)
  },
  [UPDATE_ISLOADEDMAP](state, data) {
    state.isLoadedMap = data;
  },
  [UPDATE_CLIENT](state, data) {
    state.client = data;
  },
  [UPDATE_ACTIVEMENULIST](state, data) {
    state.activeMenuList = data;
  },
  [UPDATE_ISPACKUP](state, data) {
    state.isPackUp = data;
  },
  [UPDATE_CURRENTUSER](state, data) {
    state.currentUser = data;
  },
  [UPDATE_JUMPPAGE](state, data) {
    state.jumpPage = data;
  },
  [UPDATE_ISSHOWREPLYDOM](state, data) {
    state.isShowReplyDom = data;
  },
  [UPDATE_ISSHOWALERTDOM](state, data) {
    state.isShowAlertDom = data;
  },
  [UPDATE_REPLYNUM](state, data) {
    state.replyNum = data;
  },
  [UPDATE_ALERTNUM](state, data) {
    state.alertNum = data;
  },
  [GET_AVAILABLEMENULIST](state, data) {
    state.availableMenuList = data;
  },
  [UPDATE_SYSTITLE](state, data) {
    state.sysTitle = data;
  },
  // [UPDATE_MAPREFRESH](state, data) {
  //   state.mapRefresh = data;
  // },
  // [UPDATE_MAPCENTERLNG](state, data) {
  //   state.mapCenterLng = data;
  // },
  // [UPDATE_MAPCENTERLAT](state, data) {
  //   state.mapCenterLat = data;
  // },
  [UPDATE_MAPSETTINGS](state, data) {
    state.mapSettings = data;
  },
  [UPDATE_MAPWINDOWLIST](state, payload = {
    commond: 1,
    iotKey: '',
    newData: []
  }) {
    switch (payload.commond) {
      case 1:
        function filter1(arr, key) {
          return arr.filter((item) => {
            return item.Id.indexOf(key) == -1
          })
        }
        this.state.mapWindowList = filter1(this.state.mapWindowList, payload.iotKey)
        break
      case 2:
        state.mapWindowList = [];
        break
      case 3:
        function unique3(arr) { //利用map来去重，防止用户多点显示错误
          const map = new Map()
          return arr.filter(item => !map.has(item) && map.set(item, 1))
        }
        this.state.allData.data.forEach(v => {
          if (payload.iotKey === v.Id) {
            state.mapWindowList.push(v)
          }
        })
        state.mapWindowList = unique3(state.mapWindowList)
        break
    }
  },
}